package com.hackordie.operations.queries;

import com.hackordie.commons.HackOrDieResult;
import com.hackordie.commons.game.player.UserComponent;
import com.hackordie.constants.EComponentsType;
import com.hackordie.exceptions.HackOrDieException;
import com.hackordie.operations.AHackOrDieOperationUserComponents;

public class QueryUserComponents extends AHackOrDieOperationUserComponents {

	private final int idUser;
	private final boolean allData;
	
	public QueryUserComponents(int idUser, boolean allData) {
		super();
		this.idUser = idUser;
		this.allData = allData;
	}
	
    @Override
	protected boolean checkParameters() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	protected HackOrDieResult executeOperation() throws HackOrDieException {
	    
	    UserComponent[] componentsWhitoutAcomponentData = userComponentDao.getAllUserComponents(idUser);
	    
	    if(allData) {
    	    int idComponentOnBag;
    	    EComponentsType componentType;
    	    
    	    for(int i = 0; i < componentsWhitoutAcomponentData.length; i++) {
    	        
    	        idComponentOnBag = componentsWhitoutAcomponentData[i].getIdComponentOnBag();
    	        componentType = componentsWhitoutAcomponentData[i].getComponentType();
    	        
    	        componentsWhitoutAcomponentData[i].setComponent(userComponentDao.getComponentOnBag(idComponentOnBag, componentType));
    	    }
	    }
	    result.setObject(componentsWhitoutAcomponentData);	    
	    return result;
	}
	
}
